package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueMapper tbClueMapper;

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 操作记录
     * @param clueId
     * @return
     */
    @Override
    public TableDataInfo list(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordMapper.list(clueId);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(tbClueTrackRecords);
        tableDataInfo.setTotal(1L);
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }

    /**
     * 新增线索跟进记录
     * @param clueTrackRecord
     */
    @Override
    public void add(ClueTrackRecordVo clueTrackRecord) {
        //先对线索表进行修改
        TbClue tbClue = new TbClue();
        Long clueId = clueTrackRecord.getClueId();
        String name = clueTrackRecord.getName();
        String sex = clueTrackRecord.getSex();
        Integer age = clueTrackRecord.getAge();
        String weiXin = clueTrackRecord.getWeixin();
        String qq = clueTrackRecord.getQq();
        String level = clueTrackRecord.getLevel();
        String subject = clueTrackRecord.getSubject();
        tbClue.setId(clueId);
        tbClue.setName(name);
        tbClue.setSex(sex);
        tbClue.setAge(age);
        tbClue.setWeixin(weiXin);
        tbClue.setQq(qq);
        tbClue.setStatus("2");
        tbClue.setLevel(level);
        tbClue.setSubject(subject);
        tbClueMapper.updateTbClue(tbClue);
        //再将数据添加进线索跟进记录表
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecord,tbClueTrackRecord);
        String createBy = SecurityUtils.getUsername();
        tbClueTrackRecord.setCreateBy(createBy);
        tbClueTrackRecordMapper.add(tbClueTrackRecord);
    }
}
